﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" AutoEventWireup="true" CodeBehind="Change.aspx.cs" Inherits="Ashlen.Portal.Web.Views.Account.Change" %>
<%@ Import Namespace="MvcContrib.UI.Html"%>

<asp:Content ContentPlaceHolderID="head" runat="server">
    <script src="../../Content/MicrosoftAjax.js" type="text/javascript"></script>
    <script src="../../Content/MicrosoftMvcAjax.js" type="text/javascript"></script>
    <script src="../../Content/UI/ui/ui.datepicker.js" type="text/javascript"></script>
    <link href="../../Content/UI/themes/default/ui.datepicker.css" rel="stylesheet" type="text/css" />
</asp:Content>

<asp:Content ID="Content1" ContentPlaceHolderID="MainContent" runat="server">

    <script src="../../Content/Account.js" type="text/javascript"></script>
    <script type="text/javascript">
        $(document).ready(function() {

            $("#dateOfBirth").datepicker({ onSelect: function(date)
            { }, showOn: "both", yearRange: '1945:2008', dateFormat: 'dd-MM-yy'
            });
            $("#dateOfBirth").attr('readonly', true);
        });
        
        var ddlCountries;
        var ddlStates;

        function pageLoad() {
            ddlCountries = $get("country");
            ddlStates = $get("state");
            $addHandler(ddlCountries, "change", bindOptions);
            bindOptions();
        }

        function bindOptions() {
            ddlStates.options.length = 0;
            var countryId = ddlCountries.value;

            if (countryId) {
                var url = "../Account/GetStatesForCountry/" + countryId;
                getContent(url, bindOptionResults);
            }
        }

        function bindOptionResults(data) {
            var newOption;
            var found;
            found = false;
            for (var k = 0; k < data.length; k++) {
                newOption = new Option(data[k].Name, data[k].ID);
                
                if ($get("selectedState") != null) {
                    if (data[k].ID == $get("selectedState").value) {
                        newOption.selected = true;
                        found = true;
                    }
                }
                ddlStates.options.add(newOption);
            }
            if (found == false) {
                ddlStates.value = data[0].ID;
            }
        }

        /**** should be in library ***/
        function getContent(url, callback) {
            var request = new Sys.Net.WebRequest();
            request.set_url(url);
            request.set_httpVerb("GET");
            var del = Function.createCallback(getContentResults, callback);
            request.add_completed(del);
            request.invoke();
        }

        function getContentResults(executor, eventArgs, callback) {
            if (executor.get_responseAvailable()) {
                callback(eval("(" + executor.get_responseData() + ")"));
            }
            else {
                if (executor.get_timedOut())
                    alert("Timed Out");
                else if (executor.get_aborted())
                    alert("Aborted");
            }
        }

    </script>
    <h2>
        Account Update</h2>
    <p>
        Use the form below to create a update your account.
    </p>
    <p>
        Passwords are required to be a minimum of
        <%=Html.Encode(ViewData["PasswordLength"])%>
        characters in length.<br />
        Items marked with an asterisk (*) are mandatory.<br />
    </p>   
    <%
        var errors = ViewData["errors"] as IList<string>;
        if (errors != null) {
    %>
    <ul class="error" id="errors">
        <% foreach (string error in errors) { %>
        <li>
            <%= Html.Encode(error) %></li>
        <% } %>
    </ul>
    <%
        }
    %>
    <%= Html.Hidden("selectedState")%>
    <%using (Ajax.Form("Update", new  AjaxOptions { OnSuccess = "showErrors", LoadingElementId = "myAnimatedGif", OnFailure = "showAJAXError" })) { %>
    <div>
        <table>
            <tr>               
                <td><img src="../../Images/MessageSuccess.gif" alt="Success" visible="false" id="SuccessImage" style="display: none"/></td>
                <td>
                    <div id="successDiv" style="color: Green">
                    </div>
                    <img id="myAnimatedGif" src="../../Images/loading_animated.gif" alt="Progress" visible="false"
                            style="display: none" />
                </td>
            </tr>
            <tr>
                <td>
                    Username:
                </td>
                <td>
                    <%= ViewData["username"] %>
                </td>
            </tr>
            <tr>
                <td>
                    Email:
                </td>
                <td>
                    <%= Html.TextBox("email") %>*
                </td>
            </tr>
            <tr>
                <td>
                    Password:
                </td>                
                <td>
                    <%= Html.Password("password") %>
                </td>
            </tr>
            <tr>
                <td>
                    Confirm password:
                </td>
                <td>
                    <%= Html.Password("confirmPassword") %>
                </td>
            </tr>
            <tr>
                <td>
                    Firstname:
                </td>
                <td>
                    
                    <%= Html.TextBox("firstName") %>*
                </td>
            </tr>
            <tr>
                <td>
                    Lastname:
                </td>
                <td>
                    <%= Html.TextBox("lastName") %>*
                </td>
            </tr>
            <tr>
                <td>
                    Nickname:
                </td>
                <td>
                    <%= Html.TextBox("nickName") %>
                </td>
            </tr>
            <tr>
                <td>
                    Date of Birth:
                </td>
                <td>
                    <%= Html.TextBox("dateOfBirth") %>
                                      
                </td>
            </tr>
            <tr>
                <td>
                    Sex:
                </td>
                <td>                    
                    <%= Html.DropDownList("", "sex")%>*
                </td>
            </tr>
            <tr>
                <td>
                    Mobile:
                </td>
                <td>
                    <%= Html.TextBox("mobile")%>
                </td>
            </tr>
            <tr>
                <td>
                    Phone:
                </td>
                <td>
                    <%= Html.TextBox("phone")%>
                </td>
            </tr>
            <tr>
                <td>
                    Country:
                </td>
                <td>
                    <%= Html.DropDownList("", "country")%>*
                </td>
            </tr>
            <tr>
                <td>
                    State/Town:
                </td>
                <td>
                    <select id="state" name="state"></select>*
                </td>
            </tr>
            <tr>
                <td>
                    Postcode:
                </td>
                <td>
                    <%= Html.TextBox("postcode")%>
                </td>
            </tr>
            <tr>
                <td>
                    Send Me Community Alerts:
                </td>
                <td>
                    <%= Html.CheckBox("acceptCommunityEmail", ViewState["acceptCommunityEmail"])%>
                </td>
            </tr>
            <tr>
                <td>
                    Send Me Promotions:
                </td>
                <td>
                    <%= Html.CheckBox("acceptAdvertisingEmail", ViewState["acceptAdvertisingEmail"])%>
                </td>
            </tr>
            <tr>
                <td>
                </td>
                <td>
                    <%= Html.SubmitButton("submit", "Update") %>
                </td>
            </tr>
        </table>
    </div>
    <% } %>
</asp:Content>
